import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class ControllerDemoPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return ControllerDemoStatePage();
  }
}

class ControllerDemoStatePage extends State<ControllerDemoPage> {
  final TextEditingController controller = TextEditingController(text: "初始化的值");

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('Controller例子'),
      ),
      body: Center(
        child: TextField(
          controller: controller,
          textAlign: TextAlign.center,
          style: TextStyle(fontSize: 16),
          decoration: InputDecoration(
            labelStyle: TextStyle(fontSize: 16),
            hintText: '\uE8b6 电影 / 电视剧 / 影人',
            hintStyle: TextStyle(fontSize: 16, fontFamily: 'MaterialIcons'),
            contentPadding: EdgeInsets.only(top: 8, bottom: 8),
            filled: true,
            fillColor: Colors.black12,
            border: OutlineInputBorder(
                borderSide: BorderSide.none,
                borderRadius: BorderRadius.all(Radius.circular(8))),
          ),
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          print("打印初始化的值 ${controller.text}");
          controller.text = '点击之后的值';
        },
        child: Icon(
          Icons.add,
          size: 40,
          color: Colors.white,
        ),
      ),
    );
  }
}
